package com.itheima.tlais_web_management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlais_web_management.mapper.StudentMapper;
import com.itheima.tlais_web_management.pojo.Class;
import com.itheima.tlais_web_management.pojo.Emp;
import com.itheima.tlais_web_management.pojo.PageBean;
import com.itheima.tlais_web_management.pojo.Student;
import com.itheima.tlais_web_management.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageBean list(Integer page, Integer pageSize, String name, Integer educationId, String number, Integer classId) {
        //设置分页参数
        Page<Object> startPage = PageHelper.startPage(page, pageSize);

        //执行查询
        List<Student> list = studentMapper.list(name,educationId,number,classId);
        Page<Student> emplist = (Page<Student>) list;

        //封装一个 pageBean 对象
        PageBean pageBean = new PageBean(emplist.getTotal(),emplist.getResult());
        return pageBean;
    }

    @Override
    public Student getbyid(Integer id) {
        return studentMapper.getbyid(id);
    }

    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);
    }

    @Override
    public void save(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.save(student);
    }

    @Override
    public void delete(List<Integer> ids) {
        studentMapper.delete(ids);
    }


}
